<template>
  <div class="div">
    <a-row class="top_font">
      <a-col span="7" class="">
        <a-input addon-before="操作类型：" v-model="search.type"/>
      </a-col>
      <a-col span="7">
        <a-input style="margin-left: 16px" addon-before="请求路径：" v-model="search.url"/>
      </a-col>
      <a-col span="3">
        <a-button
          style="margin-left: 48px"
          icon="search"
          type="primary"
          htmlType="submit"
          @click="searchList()"
        >查询</a-button>
      </a-col>
    </a-row>
    <a-row class="center_margin">
      <a-col span="7">
        <a-input addon-before="操作时间：" v-model="search.createTime"/>
      </a-col>
      <a-col span="7">
        <a-input style="margin-left: 16px" addon-before="操作人员：" v-model="search.userName"/>
      </a-col>
      <a-col span="3">
        <a-button
          icon="sync"
          style="margin-left: 48px"
          @click="reset()"
        >重置</a-button>
      </a-col>
    </a-row>
    <a-row class="bottom_font">
      <a-col class="title" span="3">
        日志编号
      </a-col>
      <a-col class="title" span="3">
        操作类型
      </a-col>
      <a-col class="title" span="3">
        请求路径
      </a-col>
      <a-col class="title" span="3">
        操作人员
      </a-col>
      <a-col class="title" span="3">
        操作地点
      </a-col>
      <a-col class="title" span="3">
        操作状态
      </a-col>
      <a-col class="title" span="3">
        操作日期
      </a-col>
      <a-col class="title" span="3">
        详情
      </a-col>
    </a-row>
    <a-list :data-source="data" :pagination="{onChange: (current, size) => {this.num = current, this.searchViews?this.searchInfo():this.getAll()}, showQuickJumper: true, pageSize: 15, total: totalList}">
      <a-list-item slot="renderItem" slot-scope="item">
        <a-col class="numb" span="3">
          {{ item.id }}
        </a-col>
        <a-col class="numb" span="3">
          {{ item.type }}
        </a-col>
        <a-col class="numb" span="3">
          {{ item.url }}
        </a-col>
        <a-col class="numb" span="3">
          {{ item.userName }}
        </a-col>
        <a-col class="numb" span="3">
          {{ item.accessId }}
        </a-col>
        <a-col class="numb" span="3">
          {{ item.id }}
        </a-col>
        <a-col class="numb" span="3">
          {{ item.createTime }}
        </a-col>
        <a-col class="numb" span="3">
          {{ item.accessInfo }}
        </a-col>
      </a-list-item>
    </a-list>
  </div>
</template>

<script>
import { searchLogs, getAllLogs } from '@/api/manage'
export default {
  data () {
    return {
      data: [],
      searchViews: false,
      search: { pageSize: 15, pageNum: 1, type: '', createTime: '', url: '', accessIp: '', userName: '' },
      totalList: 0,
      num: 1
    }
  },
  created () {
    this.getAll()
  },
  methods: {
    searchList () {
      // console.log(this.num)
      this.searchViews = true
      this.num = 1
      this.searchInfo()
    },
    searchInfo () {
      this.$set(this.search, 'pageNum', this.num)
      searchLogs(this.search).then((res) => {
        this.data = res.datalist
        this.totalList = Number(res.total)
        // console.log(res)
        // console.log(this.data)
      })
    },
    reset () {
      this.$set(this.search, 'pageNum', 1)
      this.$set(this.search, 'createTime', '')
      this.$set(this.search, 'type', '')
      this.$set(this.search, 'url', '')
      this.$set(this.search, 'username', '')
      this.num = 1
      if (this.searchViews) {
        this.getAll()
      }
      this.searchViews = false
      // console.log(this.num)
    },
    getAll () {
      const pageBase = { content: '', pageNum: this.num, pageSize: '15' }
      getAllLogs(pageBase).then((res) => {
        this.data = res.datalist
        this.totalList = Number(res.total)
        // console.log(res)
        // console.log(this.data)
      })
    }
  }
}
</script>

<style scoped>
.title{
  text-align: center;
}
.numb{
  text-align: center;
  word-break:break-all;
	display:-webkit-box;
	-webkit-line-clamp:1;
	-webkit-box-orient:vertical;
	overflow:hidden;
}
.div{
    padding-right: 20px;
    padding-left: 20px;
    padding-top: 20px;
    padding-bottom: 40px;
    background-color: rgb(255, 255, 255);
    width: 100%;
    height: 100%;
}
.top_font{
    font-size: larger;
}
.center_margin{
    margin-top: 10px;
    font-size: larger;
}
.img{
    height: 20px;
    width: 20px;
    border-radius: 100%;
    margin-left: 64px
}
.bottom_font{
    font-size: larger;
    margin-top: 10px;
    background-color: rgba(241, 247, 247, 0.979);

}
</style>
